package cn.antalk.top.normal.dao;


import cn.antalk.top.normal.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @Author: WackyBoy
 * @Date: 2021/12/4 19:11
 */

@Mapper
public interface TalkDao {
    @Insert("insert into talk(uid, content, create_time) values(#{uid}, #{content}, #{create_time})")
    int pushTalk(Talk talk);

    @Select("select * from talk limit #{page}, #{count}")
    List<Talk> getTalkByPageAndCount(@Param("page") int page, @Param("count") int count);

    @Select("select * from user where uid = #{uid}")
    User getUserByUid(@Param("uid") int uid);

    @Select("select uid from `like` where talk_id = #{talk_id} ")
    List<Integer> getLike2UidByTalkId(@Param("talk_id") Integer talk_id);

    @Select("select * from `like` where uid = #{uid} and talk_id = #{talk_id}")
    List<Like> hasLike(@Param("uid") int uid, @Param("talk_id") int talk_id);

    // not sure isRight???
    @Update("update `like` set islike = #{islike} where uid = #{uid} and talk_id = #{talk_id} ")
    int changeLikeState(@Param("uid") int uid, @Param("talk_id") int talk_id, @Param("islike") int islike);

    @Insert("insert into `like`(uid, talk_id) values(#{uid}, #{talk_id}) ")
    int insertLikeByUidAndTalkId(@Param("uid") int uid, @Param("talk_id") int talk_id);

    @Update("update `talk` set like_count = #{like_count} where talk_id = #{talk_id}")
    void changeTalkLikeCount(@Param("talk_id") int talk_id, @Param("like_count") int like_count);

    @Select("select * from talk where talk_id = #{talk_id}")
    Talk getTalkByTalkId(@Param("talk_id") int talk_id);

    @Select("select * from comment where talk_id = #{talkId}")
    List<Comment> getTalkCommentByTalkId(@Param("talkId") int talkId);

    @Insert("insert into comment(parent_id, talk_id, from_uid, to_uid, content, create_time) values(0, #{talk_id}, #{from_uid}, #{to_uid}, #{content}, #{create_time})")
    int updateComment(Comment comment);

    @Update("update talk set comment_count = #{count} where talk_id = #{talkId}")
    void talkCommentAdd(@Param("talkId") int talkId, @Param("count") int count);

    @Select("select * from comment where comment_id = #{comment_id} ")
    Comment getCommentByCommentId(@Param("comment_id") int comment_id);

    @Update("update comment set like_count = #{like_count} where comment_id = #{comment_id}")
    void CommentLikeCount(@Param("comment_id") int comment_id, @Param("like_count") int like_count);

    @Insert("insert into `replylike`(uid, comment_id, likeStatus) values(#{u_id}, #{comment_id}, #{likeStatus}) ")
    int SetReplyLikeStatusOpp(@Param("comment_id") int comment_id, @Param("u_id") int u_id, @Param("likeStatus") int likeStatus);



    @Select("select * from replylike where uid = #{u_id} and comment_id = #{comment_id}")
    ReplyLike getReplyLikeByUidAndCommentId(@Param("comment_id") int comment_id, @Param("u_id") int u_id);

    @Update("update `replylike` set likeStatus = #{likeStatus} where uid = #{u_id} and comment_id = #{comment_id} ")
    void updateReplyLike(@Param("comment_id") int comment_id, @Param("u_id") int u_id, @Param("likeStatus") int likeStatus);



//    @Insert("insert into talk(uid, content, create_time) values(#{uid}, #{content}, #{create_time})")
//    int pushTalk1(@Param("uid") int uid, @Param("content") String content, @Param("create_tmie") Date create_time);
}
